package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.PmsProductAttribute;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.PmsProductAttributeDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface PmsProductAttributeMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn
            .columnList(id, productAttributeCategoryId, name, selectType, inputType, inputList, sort, filterType, searchType, relatedStatus, handAddStatus, type);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(PmsProductAttribute record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(productAttributeCategoryId).equalTo(record::getProductAttributeCategoryId)
                  .set(name).equalTo(record::getName)
                  .set(selectType).equalTo(record::getSelectType)
                  .set(inputType).equalTo(record::getInputType)
                  .set(inputList).equalTo(record::getInputList)
                  .set(sort).equalTo(record::getSort)
                  .set(filterType).equalTo(record::getFilterType)
                  .set(searchType).equalTo(record::getSearchType)
                  .set(relatedStatus).equalTo(record::getRelatedStatus)
                  .set(handAddStatus).equalTo(record::getHandAddStatus)
                  .set(type).equalTo(record::getType);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(PmsProductAttribute record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(productAttributeCategoryId).equalToWhenPresent(record::getProductAttributeCategoryId)
                  .set(name).equalToWhenPresent(record::getName)
                  .set(selectType).equalToWhenPresent(record::getSelectType)
                  .set(inputType).equalToWhenPresent(record::getInputType)
                  .set(inputList).equalToWhenPresent(record::getInputList)
                  .set(sort).equalToWhenPresent(record::getSort)
                  .set(filterType).equalToWhenPresent(record::getFilterType)
                  .set(searchType).equalToWhenPresent(record::getSearchType)
                  .set(relatedStatus).equalToWhenPresent(record::getRelatedStatus)
                  .set(handAddStatus).equalToWhenPresent(record::getHandAddStatus)
                  .set(type).equalToWhenPresent(record::getType);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<PmsProductAttribute> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("PmsProductAttributeResult")
    Optional<PmsProductAttribute> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "PmsProductAttributeResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "product_attribute_category_id", property = "productAttributeCategoryId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "select_type", property = "selectType", jdbcType = JdbcType.INTEGER),
            @Result(column = "input_type", property = "inputType", jdbcType = JdbcType.INTEGER),
            @Result(column = "input_list", property = "inputList", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "filter_type", property = "filterType", jdbcType = JdbcType.INTEGER),
            @Result(column = "search_type", property = "searchType", jdbcType = JdbcType.INTEGER),
            @Result(column = "related_status", property = "relatedStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "hand_add_status", property = "handAddStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "type", property = "type", jdbcType = JdbcType.INTEGER)
    })
    List<PmsProductAttribute> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, pmsProductAttribute, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, pmsProductAttribute, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(PmsProductAttribute record) {
        return MyBatis3Utils.insert(this::insert, record, pmsProductAttribute, c ->
                c.map(productAttributeCategoryId).toProperty("productAttributeCategoryId")
                 .map(name).toProperty("name")
                 .map(selectType).toProperty("selectType")
                 .map(inputType).toProperty("inputType")
                 .map(inputList).toProperty("inputList")
                 .map(sort).toProperty("sort")
                 .map(filterType).toProperty("filterType")
                 .map(searchType).toProperty("searchType")
                 .map(relatedStatus).toProperty("relatedStatus")
                 .map(handAddStatus).toProperty("handAddStatus")
                 .map(type).toProperty("type")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(PmsProductAttribute record) {
        return MyBatis3Utils.insert(this::insert, record, pmsProductAttribute, c ->
                c.map(productAttributeCategoryId)
                 .toPropertyWhenPresent("productAttributeCategoryId", record::getProductAttributeCategoryId)
                 .map(name).toPropertyWhenPresent("name", record::getName)
                 .map(selectType).toPropertyWhenPresent("selectType", record::getSelectType)
                 .map(inputType).toPropertyWhenPresent("inputType", record::getInputType)
                 .map(inputList).toPropertyWhenPresent("inputList", record::getInputList)
                 .map(sort).toPropertyWhenPresent("sort", record::getSort)
                 .map(filterType).toPropertyWhenPresent("filterType", record::getFilterType)
                 .map(searchType).toPropertyWhenPresent("searchType", record::getSearchType)
                 .map(relatedStatus).toPropertyWhenPresent("relatedStatus", record::getRelatedStatus)
                 .map(handAddStatus).toPropertyWhenPresent("handAddStatus", record::getHandAddStatus)
                 .map(type).toPropertyWhenPresent("type", record::getType)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<PmsProductAttribute> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, pmsProductAttribute, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<PmsProductAttribute> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, pmsProductAttribute, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<PmsProductAttribute> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, pmsProductAttribute, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<PmsProductAttribute> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, pmsProductAttribute, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(PmsProductAttribute record) {
        return update(c ->
                c.set(productAttributeCategoryId).equalTo(record::getProductAttributeCategoryId)
                 .set(name).equalTo(record::getName)
                 .set(selectType).equalTo(record::getSelectType)
                 .set(inputType).equalTo(record::getInputType)
                 .set(inputList).equalTo(record::getInputList)
                 .set(sort).equalTo(record::getSort)
                 .set(filterType).equalTo(record::getFilterType)
                 .set(searchType).equalTo(record::getSearchType)
                 .set(relatedStatus).equalTo(record::getRelatedStatus)
                 .set(handAddStatus).equalTo(record::getHandAddStatus)
                 .set(type).equalTo(record::getType)
                 .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(PmsProductAttribute record) {
        return update(c ->
                c.set(productAttributeCategoryId).equalToWhenPresent(record::getProductAttributeCategoryId)
                 .set(name).equalToWhenPresent(record::getName)
                 .set(selectType).equalToWhenPresent(record::getSelectType)
                 .set(inputType).equalToWhenPresent(record::getInputType)
                 .set(inputList).equalToWhenPresent(record::getInputList)
                 .set(sort).equalToWhenPresent(record::getSort)
                 .set(filterType).equalToWhenPresent(record::getFilterType)
                 .set(searchType).equalToWhenPresent(record::getSearchType)
                 .set(relatedStatus).equalToWhenPresent(record::getRelatedStatus)
                 .set(handAddStatus).equalToWhenPresent(record::getHandAddStatus)
                 .set(type).equalToWhenPresent(record::getType)
                 .where(id, isEqualTo(record::getId))
        );
    }
}
